﻿/*
 * @Author: Dreamy Icecream 
 * @Date: 2020-12-31 10:09:02 
 * @Description: 边缘检测
 * @Last Modified by: Dreamy Icecream
 * @Last Modified time: 2020-12-31 11:19:08
 */

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EdgeDectection : PostEffectsBase {

    public Shader edgeDetectionShader;

    private Material edgeDetectionMaterial = null;
    public Material material {
        get {
            this.edgeDetectionMaterial = this.CheckShaderAndCreateMaterial (this.edgeDetectionShader, this.edgeDetectionMaterial);
            return this.edgeDetectionMaterial;
        }
    }

    /** 边缘显示的比重 */
    [Range (0, 1)]
    public float edgesOnly = 0.0f;

    /** 描边颜色 */
    public Color edgeColor = Color.black;

    /** 背景颜色 */
    public Color backgroundColor = Color.white;

    private void OnRenderImage (RenderTexture src, RenderTexture dest) {
        if (this.material != null) {
            this.material.SetFloat ("_EdgeOnly", this.edgesOnly);
            this.material.SetColor ("_EdgeColor", this.edgeColor);
            this.material.SetColor ("_BackgroundColor", this.backgroundColor);

            Graphics.Blit (src, dest, this.material);

        } else {
            Graphics.Blit (src, dest);
        }
    }

}